﻿/**
* jQuery EasyUI 1.4.3
* Copyright (c) 2009-2015 www.jeasyui.com. All rights reserved.
*
* Licensed under the GPL license: http://www.gnu.org/licenses/gpl.txt
* To use it on other terms please contact us at info@jeasyui.com
* http://www.jeasyui.com/license_commercial.php
*
* jQuery EasyUI datagrid 组件扩展
* jeasyui.extensions.datagrid.moreEditors.js
* 开发 流云
* 由 落阳 整理和二次扩展
* 最近更新：2015-12-03
*
* 依赖项：
*   1、jquery.jdirk.js
*   2、jeasyui.extensions.validatebox.rules.js
*   3、my97日期插件
*
* Copyright (c) 2015 ChenJianwei personal All rights reserved.
*/
(function ($) {

    var editors = $.fn.datagrid.defaults.editors,
        text_init = editors.text.init,
        textarea_init = editors.textarea.init,
        checkbox_init = editors.checkbox.init,
        textbox_init = editors.textbox.init,
        validatebox_init = editors.validatebox.init,
        numberbox_init = editors.numberbox.init,
        datebox_init = editors.datebox.init,
        combobox_init = editors.combobox.init,
        combotree_init = editors.combotree.init;

    //  扩展 easyui-datagrid editors-integerbox 编辑器；
    //  用于自动验证 整数 内容；
    $.extend(editors, {
        integerbox: {
            init: function (target, options) {
                var editor = $("<input type=\"text\" class=\"datagrid-editable-input\">").appendTo(target);
                editor.numberbox($.extend(options, {
                    validType: ["integer"]
                })).numberbox("textbox").addClass("datagrid-editable-input");
                return editor;
            },
            destroy: function (target) {
                $(target).numberbox("destroy");
            },
            getValue: function (target) {
                return $(target).numberbox("getValue");
            },
            setValue: function (target, newValue) {
                $(target).numberbox("setValue", newValue);
            },
            resize: function (target, width) {
                $(target).numberbox("resize", width);
            }
        }
    });

    $.extend(editors, {
        yyyyMMbox: {
            init: function (target, options) {
                var editor = $("<input type=\"text\" class=\"datagrid-editable-input\">").appendTo(target);
                editor.validatebox(options).addClass("datagrid-editable-input Wdate").click(function () {
                    WdatePicker({
                        readOnly: true,
                        dateFmt: "yyyy-MM",
                    })
                });
                return editor;
            },
            getValue: function (target) {
                return $(target).val();
            },
            setValue: function (target, newValue) {
                $(target).val(newValue);
            },
            resize: function (target, width) {
                $(target)._outerWidth(width)._outerHeight(22);
            }
        }
    });

    $.extend(editors, {
        yyyyMMddbox: {
            init: function (target, options) {
                var editor = $("<input type=\"text\" class=\"datagrid-editable-input\">").appendTo(target);
                editor.validatebox(options).addClass("datagrid-editable-input Wdate").click(function () {
                    WdatePicker({
                        readOnly: true,
                        dateFmt: "yyyy-MM-dd",
                    })
                });
                return editor;
            },
            getValue: function (target) {
                return $(target).val();
            },
            setValue: function (target, newValue) {
                $(target).val(newValue);
            },
            resize: function (target, width) {
                $(target)._outerWidth(width)._outerHeight(22);
            }
        }
    });

    $.extend(editors, {
        my97box: {
            init: function (target, options) {
                var editor = $("<input type=\"text\" class=\"datagrid-editable-input\">").appendTo(target);
                editor.validatebox(options).addClass("datagrid-editable-input Wdate").click(function () {
                    WdatePicker({
                        readOnly: true,
                        dateFmt: "yyyy-MM-dd HH:mm:ss",
                    })
                });
                return editor;
            },
            getValue: function (target) {
                return $(target).val();
            },
            setValue: function (target, newValue) {
                $(target).val(newValue);
            },
            resize: function (target, width) {
                $(target)._outerWidth(width)._outerHeight(22);
            }
        }
    });

})(jQuery);